/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package fr.jade.examples.fraclite.orb.consoleha;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.objectweb.fractal.api.control.BindingController;


public class ClientImpl implements Runnable, BindingController {

	private Service s = null;

	public void run () {
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			try {
			  System.out.println(">");
        s.print(br.readLine());
      } catch (IOException e) {
        e.printStackTrace();
      }
		}
	}

	public String[] listFc () {
		return new String[] { "s" };
	}

	public Object lookupFc (final String cItf) {
		if (cItf.equals("s")) {
			return s;
		}
		return null;
	}

	public void bindFc (final String cItf, final Object sItf) {
		if (cItf.equals("s")) {
			s = (Service)sItf;
		}
	}

	public void unbindFc (final String cItf) {
		if (cItf.equals("s")) {
			s = null;
		}
	}
}
